# -*- coding: utf-8 -*-
"""
-------------------------------------------------
# @Project  :pythonProject
# @File     :skelton
# @Date     :2021/10/22 14:16
# @Author   :zhumenglong
# @Software :PyCharm
-------------------------------------------------
"""
from wareHouse import *
class Skelton:
    def __init__(self, file_path, Index_path, goal_path):
        self.file_path = file_path
        self.Index_path = Index_path
        self.goal_path = goal_path

    def get_keypoint1(self):
        with open(self.Index_path, 'r', encoding='utf-8') as fp:
            while True:
                file_name = fp.readline()[:-1]
                json_name = ""
                pict_name = ""
                if len(file_name) > 0:
                    json_name = self.file_path + file_name + '_info.json'
                    pict_name = self.file_path + file_name + '.jpg'
                    Skelton.draw_pic_jpg(self, file_name, json_name, pict_name)

                else:
                    break

    def draw_pic_jpg(self, file_name, json_name, pict_name):
        with open(json_name, 'rb') as f:
            json_info = json.loads(f.read())
            img_info = method.cv2_imread(pict_name, -1)
            for i in json_info:
                if i == "box":
                    cat_name = "ped_box"
                    for num in json_info[i]:
                        xmin = int(num['x'])
                        ymin = int(num['y'])
                        xmax = int(num['x']) + int(num['width'])
                        ymax = int(num['y']) + int(num['height'])
                        conf = num['conf']

                        x = 0
                        y = 250
                        z = 0
                        color = (x, y, z)
                        cv2.rectangle(img_info, (int(xmin), int(ymin)), (int(xmax), int(ymax)), color, 2)
                        cv2.putText(img_info,"width:"+str(int(num['width'])),(int(xmin)+200, int(ymin)),
                                    cv2.FONT_HERSHEY_SIMPLEX,1,color,2)
                        cv2.putText(img_info, "height:" + str(int(num['height'])), (int(xmin) + 200, int(ymin) + 40),
                                    cv2.FONT_HERSHEY_SIMPLEX, 1, color, 2)
                        cv2.putText(img_info, "conf:" + str(conf), (int(xmin) + 200, int(ymin) + 80),
                                    cv2.FONT_HERSHEY_SIMPLEX, 1, color, 2)
                        font = cv2.FONT_HERSHEY_SIMPLEX
                        cv2.putText(img_info, cat_name, (int(xmin), int(ymin)), font, 1, color, 2)
            method.create_path(self.goal_path)

            method.cv2_imwrite_jpg("./" + self.goal_path + "/" + file_name + ".jpg", img_info)